home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / bix01.zip / STRINGS.LIB < prev    next >
Text File  |  1986-07-07  |  2KB  |  95 lines

  1.  
  2.  
  3. {$R-} { turn off range checking (if on) }
  4. {$V-} { turn off string parm length checking }
  5.  
  6. {
  7.         procedures and functions in this library
  8.  
  9.   LowToUp            converts string to uppercase
  10.   Strip              removes any leading characters
  11.   Parse              gets next word out of string
  12.   Replace            replaces all instance of one substring with another
  13.  
  14. }
  15.  
  16. type
  17.   BigStr             = string[255];
  18.   SetOfChar          = set of Char;
  19.  
  20. procedure LowToUp(var TStr : BigStr);
  21. {
  22.        purpose       converts TStr to all upper case
  23.        last update   23 Jun 85
  24. }
  25. var
  26.   Len,Indx           : Integer;
  27. begin
  28.   Len := Length(TStr);
  29.   for Indx := 1 to Len do
  30.     TStr[Indx] := UpCase(TStr[Indx])
  31. end; { of proc LowToUp }
  32.  
  33. procedure Strip(var Line : BigStr; var Len : Integer; Break : SetOfChar);
  34. {
  35.        purpose       pull out all chars in Break from start of Line
  36.        last update   09 Jul 85
  37. }
  38. var
  39.   Indx               : Integer;
  40. begin
  41.   Len := Length(Line);
  42.   if Len > 0 then begin
  43.     Indx := 0;
  44.     while (Line[Indx+1] in Break) and (Indx < Len) do
  45.       Indx := Indx + 1;
  46.     Delete(Line,1,Indx);
  47.     Len := Len - Indx;
  48.   end
  49. end; { of proc Strip }
  50.  
  51. procedure Parse(var Line,Word : BigStr; Break : SetOfChar);
  52. {
  53.        purpose       removes first word in Line and returns it in Word
  54.        last update   23 Jun 85
  55. }
  56. var
  57.   Len,Indx           : Integer;
  58. begin
  59.   Word := '';
  60.   Strip(Line,Len,Break);
  61.   if Len = 0
  62.     then Exit;
  63.   Indx := 0;
  64.   while not (Line[Indx+1] in Break) and (Indx < Len) do
  65.     Indx := Indx + 1;
  66.   Word := Copy(Line,1,Indx);
  67.   Delete(Line,1,Indx);
  68.   Strip(Line,Len,Break)
  69. end; { of proc Parse }
  70.  
  71. procedure Replace(var Target : BigStr; OldStr,NewStr : BigStr; MaxLen : Byte);
  72. {
  73.        purpose       look for all instances of OldStr and replace with NewStr
  74.        last update   09 Jul 85
  75. }
  76. var
  77.   TarLen,OldLen,IncLen,Indx
  78.                      : Integer;
  79. begin
  80.   TarLen := Length(Target);
  81.   OldLen := Length(OldStr);
  82.   IncLen := Length(NewStr) - OldLen;
  83.   Indx := Pos(OldStr,Target);
  84.   while Indx > 0 do begin
  85.     if TarLen + IncLen <= MaxLen then begin
  86.       Delete(Target,Indx,OldLen);
  87.       Insert(NewStr,Target,Indx);
  88.       TarLen := TarLen + IncLen;
  89.       Indx := Pos(OldStr,Target)
  90.     end
  91.     else Indx := 0
  92.   end
  93. end; { of proc Replace }
  94.  
  95.